﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace SpriteWithXNA
{
    class MyCharacter :MySprite
    {
         public delegate void KeyPressedHandler(object sender,
            Keys key);
        public event KeyPressedHandler KeyPressed;

        public MyCharacter(Texture2D[] _inputtexture2d, float _inputx, float _inputy)
        {
            texture2d = _inputtexture2d;
            x = _inputx;
            y = _inputy;
            itexture2d = 0;

        }



        Keys[] prevKeys = new Keys[0];
        public Keys GetNewKeyPressed(Keys[] prevKeys, Keys[] keys)
        {
            throw new NotSupportedException("Coding by yourself");
        }

        public override void Update(GameTime gameTime)
        {
            // Get state of the keyboard
            KeyboardState state = Keyboard.GetState();

            // Do events
            if (this.KeyPressed != null)
                this.KeyPressed(this, this.GetNewKeyPressed(
                    prevKeys, state.GetPressedKeys()));
            prevKeys = state.GetPressedKeys();

            // Moving with iteraction
            if (state.IsKeyDown(Keys.Left))
            {   if(x>0)
                x -= 5;
            else x=x;
            }
            else if (state.IsKeyDown(Keys.Right))
            {
                if ((x + 50) < 768)
                    x += 5;
                else x = x;
            }
            else if (state.IsKeyDown(Keys.Up))
            {
                if(y>0)
                y -= 5;
                else y=y;
            }
            else if (state.IsKeyDown(Keys.Down))
            {
                if((y+96)<764)
                y += 5;
                else y=y;
            }
            _itexture2d = (_itexture2d + 1) % ntexture2d;
        }

    }
}
